export const convertDevices = (devices) => {
    const res = [];
    devices.forEach(item => {
       res.push({
           "deviceName": item["deviceName"],
           "deviceNumber": item["deviceNumber"],
           "deviceType": item["deviceType"],
           "deviceUnit": item["deviceUnit"],
           "deviceAddress": item["deviceAddress"],
           "statisticValue": item["statistics"][0]["statisticValue"],
           "statisticPhoto": item["statistics"][0]["statisticPhoto"],
       })
    });
    return res;
}

export const convertStatistics = (devices) => {
    const res = [];
    devices.forEach(device => {
        const per = [];
        device['statistics'].forEach(item => {
            per.push({
                'statisticValue': item["statisticValue"],
                'createTime': item['createTime'],
                'time': item['createTime'].slice(0, 19),
                'statisticPhoto': item['statisticPhoto']
            })
        });
        per.sort((a, b) => {
            return new Date(a['createTime']).getTime() - new Date(b['createTime']).getTime();
        })
        res.push(per);
    });
    return res;
}

export const getChartType = (chartName) => {
    switch (chartName) {
        case "土壤温度":
        case "土壤pH值":
            return "bar";
        default:
            return "line";
    }
}